home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 118_01.zip / FILE.DOC < prev    next >
Text File  |  1993-06-03  |  3KB  |  102 lines

  1. .cm File primitives for Software Tools
  2. .cm source:  file.doc
  3. .cm version: August 9, 1981
  4. .bp 1
  5. .rm 60
  6. .pl 66
  7. .he 'file.doc'File primitives for Software Tools'%'
  8. .fo ''page #''
  9.  
  10. .ti +3
  11. This file discusses the file primitives
  12. for the software tools.
  13.  
  14. .ul
  15. file open routine
  16.  
  17. .ti +3
  18. READ, WRITE, READWRITE, and APPEND are global constants known
  19. to all programs.
  20.  
  21. .ti +3
  22. WRITE access implies erasing the file first.
  23. READWRITE and APPEND access are currently illegal.
  24.  
  25. .ti +3
  26. If name = TERMINAL  then open()
  27. must assign the I/O to the user's console.
  28. If name is PRINTER then open() must assign the I/O to the
  29. line printer.
  30. Note that because BDS C truncates names at 8 characters,
  31. the name TERMINAL is the same as the names TERMINAL_IN and
  32. TERMINAL_OUT.
  33.  
  34. .ti +3
  35. open() returns unit numbers to the user.
  36. Units may be assigned to disk files, the console, or the
  37. line printer.
  38. open() never returns unit < SYS_STD.
  39.  
  40. .nf
  41. Unit 1 is reserved for standard input.
  42. Unit 2 is reserved for standard output.
  43. Unit 3 is reserved for error output.
  44. Unit 4 is reserved for the console.
  45. Unit 5 is reserved for the line printer.
  46. .fi
  47.  
  48. .ti +3
  49. open()  might save the file name for the software tools
  50. error routines.
  51. At present it does not do so.
  52.  
  53. .ti +3
  54. The system maintains the following file information:
  55.  
  56.     int sys_spec [SYS_STD + MAXOFILES];
  57.  
  58.     int sys_bufp [SYS_STD + MAXOFILES];
  59.  
  60.     int sys_bufn [SYS_STD + MAXOFILES];
  61.  
  62. .ti +3
  63. As you can see, there is one entry in each array for each unit.
  64. If sys_bufp [unit] != ERR then I/O is assigned to the file
  65. whose buffer is sys_bufp [unit].
  66. Otherwise, if sys_spec [unit] != ERR then I/O is assigned to
  67. either special unit 3 (the console) or 4 (the line printer).
  68. If sys_bufp [unit] == sys_spec [unit] == ERR then the
  69. unit is not open.
  70.  
  71. .ti +3
  72. Note that both sys_bufp [unit] and sys_spec [unit] may be
  73. non-ERR.
  74. In this case the unit is NOT a special file, it is a
  75. disk file.
  76. In other words, sys_bufp [] is checked before sys_spec []
  77. in getch1() and putch1() and close() and flush().
  78. This is somewhat of a kludge, but it makes open() simpler.
  79.  
  80. .ti +3
  81. The array sys_bufn [unit] is used only by open() and close().
  82. sys_bufn [] keeps track of which disk files
  83. (0 -- (MAXOFILES - 1))
  84. have been assigned.
  85. Close() uses sys_bufn [] to deassign disk files.
  86. Sys_bufn [] may not really be needed, but without it
  87. close() would have to do some hairy pointer subtraction
  88. and division on sys_bufp [] in order to figure out what
  89. disk file was being closed.
  90. It seems simpler to use sys_bufn [].
  91.  
  92. .ul
  93. system initialization routine
  94.  
  95. .ti +3
  96. initst() initializes all system data areas.
  97. It puts the command line arguments in sys_args[] and
  98. puts the number of command line arguments in sys_narg.
  99. It redirects I/O if requested on the command line.
  100. This is done by calling _assign() which in turn updates
  101. the arrays sys_spec [], sys_bufp [] and sys_bufn [].
  102.